/*
 * CManager.h
 *
 *  Created on: 2016-4-14
 *      Author: root
 */

#ifndef CSINGLETHREADMANAGER_H_
#define CSINGLETHREADMANAGER_H_
#include"CMultiThreadManager.h"
#if USE_THREAD_MANAGER
#include<list>
typedef struct _WORKINFO{
thrfunc*func;//需执行的线程    
void*usrdata;//用户数据
time_t realworktime;//真实开始工作时间
time_t nextworktime;//下一次执行时间
int    cycle;//周期
int    type;//0 实际开始执行时间+周期 1执行结束时间+周期
}WORKINFO;
typedef struct std::list<WORKINFO> WORKINFOLIST;
class CSingleThreadManager{
//线程锁
    PublicLock m_Thread_Mutex;
    ThreadInfo m_ThreadInfo;
//运行队列
    WORKINFOLIST m_worklist;
protected:

public:
    char m_ThreadMode[40];
    int  m_ThreadRunning;
public:
    CSingleThreadManager();
    virtual ~CSingleThreadManager();
//设置工作函数    
    void SetWorkFunc(thrfunc*funfunc,void*usrdata,int cycle,int type);
    void StartWorkThread();
    void StopWorkThread();
    static  void*WorkThread(void*argv);
    void RunWorkThreadMain();
//返回据下次最快等待周期    
    int RunOnce();
    void Lock();
    void UnLock();
//更新线程状态
    void UpdateThreadStatus(pthread_t threadid,ThreadStatus status);
//线程相关
public:
//线程是否开启停止标志    
    bool IsThreadRunningFlag();
//是否所有线程运行着
    bool IsAllThreadsRunning();
//是否所有线程运行着
    bool IsAllThreadsStopped();
};
#endif
#endif /* CMANAGER_H_ */
